package List$Stack$queue;

/**
 * 合并有序队列问题
 */
public class MergeSortedArray {
    public void merge(int[] nums1, int m, int[] nums2, int n) {
        int[] result = new int[m+n];
        int k = 0;
        int j = 0;
        int cnt = 0;
        while (k < m && j < n){
            if (nums1[k] <= nums2[j]){
                result[cnt++] = nums1[k++];
            } else {
                result[cnt++] = nums2[j++];
            }
        }
        while (k < m) result[cnt++] = nums1[k++];
        while (j < n) result[cnt++] = nums2[j++];

        for (int i = 0; i < cnt; i++) nums1[i] = result[i];
    }
}
